const REAccount = {
  // 登录账号名
  // new RegExp('^[a-zA-Z0-9]{1,2}$', '').toString();
  username: (min, max) => {
    let pattern = String.raw`^[a-zA-Z0-9_\-]{` + min + ',' + max + '}$';
    let msg = '支持大小写字母数字_-,' + min + '-' + max + '位';
    return {
      reg: new RegExp(pattern, ''),
      msg,
    };
  },
  // 真实姓名
  realname: (min, max) => {
    let pattern = String.raw`^[\u4e00-\u9fa5]{` + min + ',' + max + '}$';
    let msg = '支持中文,' + min + '-' + max + '位';
    return {
      reg: new RegExp(pattern, ''),
      msg,
    };
  },
  // 昵称
  nickname: (min, max) => {
    let pattern = String.raw`^[\u4e00-\u9fa5A-Za-z0-9_\-\.\+\^]{` + min + ',' + max + '}$';
    let msg = '支持中文大小写字母数字_-.+^,' + min + '-' + max + '位';
    return {
      reg: new RegExp(pattern, ''),
      msg,
    };
  },
  // 密码
  password: (min, max, level = 3) => {
    let pattern = '';
    let msg = '异常校验';
    switch (level) {
      case 0:
        pattern = String.raw`^(?=.*[A-Za-z])(?=.*\d)[A-Za-z0-9]{` + min + ',' + max + '}$';
        msg = '至少含有一个字母和一个数字,' + min + '-' + max + '位';
        break;
      case 1:
        pattern =
          String.raw`^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z0-9@$!%*#?&]{` +
          min +
          ',' +
          max +
          '}$';
        msg = '至少含有一个字母一个数字一个特殊字符@$!%*#?&,' + min + '-' + max + '位';
        break;
      case 2:
        pattern = String.raw`^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z0-9]{` + min + ',' + max + '}$';
        msg = '至少一个数字 并同时包含大小写字母,' + min + '-' + max + '位';
        break;
      case 3:
        pattern =
          String.raw`^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$#!%*?&#_\-])[A-Za-z0-9@$!%*?&#_\-]{` +
          min +
          ',' +
          max +
          '}$';
        msg = '包含大小写数字和特殊字符@$#!%*?&#_-,' + min + '-' + max + '位';
        break;
    }
    return {
      reg: pattern ? new RegExp(pattern, '') : '',
      msg,
    };
  },
  // 手机号码
  mobile: () => {
    let pattern = String.raw`^1(3|4|5|6|7|8|9)\d{9}$`;
    let msg = '仅支持11位正确手机号码';
    return {
      reg: new RegExp(pattern, ''),
      msg,
    };
  },
  // 身份证
  idCard: () => {
    let pattern = String.raw`^([1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2})$`;
    let msg = '身份证格式错误';
    return {
      reg: new RegExp(pattern, ''),
      msg,
    };
  },
};

export default REAccount;
